package basics;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Reflection101Demo {
    public void setColor(Object obj, String color) {
        Class cls = obj.getClass();
        try {
            Method mtd = cls.getMethod("setColor", String.class);
            System.out.println(mtd.getModifiers());
            mtd.invoke(obj, color);
        } catch (NoSuchMethodException ex) {
            System.out.println("There is no such method ");
        } catch (IllegalAccessException ex) {
            System.out.println("The caller don't have access right to the desried method");
        } catch (InvocationTargetException exception) {

        }
    }

    public static void main(String[] args) {
        Reflection101Demo demo = new Reflection101Demo();
        Reflection101 reflection101 = new Reflection101();
        demo.setColor(reflection101, "Yellow");
        System.out.println(reflection101.getColor());
    }
}
